x11: Make fallback cursor code not use pixmaps
authorBenjamin Otte <otte@redhat.com>
Fri, 27 Aug 2010 13:09:49 +0000 (15:09 +0200)
committerBenjamin Otte <otte@redhat.com>
Sun, 26 Sep 2010 13:11:30 +0000 (15:11 +0200)
The fallback code for when XCursor wasn't available was still using
GdkPixmap to create the bitmaps.

gdk/x11/gdkcursor-x11.c
gdk/x11/gdkprivate-x11.h
gdk/x11/gdkwindow-x11.c

index 13e0c1cbb937bcfaea1f7578afa0536573b09e13..d4d44eca4dfefdc7e00d3465ab458cfc492f1a60 100644 (file)
@@ -805,8 +805,9 @@ gdk_display_get_default_cursor_size (GdkDisplay *display)
 #else
 
 static GdkCursor*
-gdk_cursor_new_from_pixmap (GdkPixmap      *source,
-                           GdkPixmap      *mask,
+gdk_cursor_new_from_pixmap (GdkDisplay     *display,
+                            Pixmap          source_pixmap,
+                           Pixmap          mask_pixmap,
                            const GdkColor *fg,
                            const GdkColor *bg,
                            gint            x,
@@ -814,20 +815,12 @@ gdk_cursor_new_from_pixmap (GdkPixmap      *source,
 {
   GdkCursorPrivate *private;
   GdkCursor *cursor;
-  Pixmap source_pixmap, mask_pixmap;
   Cursor xcursor;
   XColor xfg, xbg;
-  GdkDisplay *display;
 
-  g_return_val_if_fail (GDK_IS_PIXMAP (source), NULL);
-  g_return_val_if_fail (GDK_IS_PIXMAP (mask), NULL);
   g_return_val_if_fail (fg != NULL, NULL);
   g_return_val_if_fail (bg != NULL, NULL);
 
-  source_pixmap = GDK_PIXMAP_XID (source);
-  mask_pixmap   = GDK_PIXMAP_XID (mask);
-  display = GDK_PIXMAP_DISPLAY (source);
-
   xfg.pixel = fg->pixel;
   xfg.red = fg->red;
   xfg.blue = fg->blue;
@@ -862,7 +855,7 @@ gdk_cursor_new_from_pixbuf (GdkDisplay *display,
                            gint        y)
 {
   GdkCursor *cursor;
-  GdkPixmap *pixmap, *mask;
+  cairo_surface_t *pixmap, *mask;
   guint width, height, n_channels, rowstride, data_stride, i, j;
   guint8 *data, *mask_data, *pixels;
   GdkColor fg = { 0, 0, 0, 0 };
@@ -913,9 +906,9 @@ gdk_cursor_new_from_pixbuf (GdkDisplay *display,
       
   screen = gdk_display_get_default_screen (display);
 
-  pixmap = gdk_pixmap_new (gdk_screen_get_root_window (screen), 
-                          width, height, 1);
-  cr = gdk_cairo_create (pixmap);
+  pixmap = _gdk_x11_window_create_bitmap_surface (gdk_screen_get_root_window (screen), 
+                                                 width, height);
+  cr = cairo_create (pixmap);
   image = cairo_image_surface_create_for_data (data, CAIRO_FORMAT_A1,
                                                width, height, data_stride);
   cairo_set_source_surface (cr, image, 0, 0);
@@ -924,9 +917,9 @@ gdk_cursor_new_from_pixbuf (GdkDisplay *display,
   cairo_paint (cr);
   cairo_destroy (cr);
  
-  mask = gdk_pixmap_new (gdk_screen_get_root_window (screen), 
-                        width, height, 1);
-  cr = gdk_cairo_create (mask);
+  mask = _gdk_x11_window_create_bitmap_surface (gdk_screen_get_root_window (screen), 
+                                               width, height);
+  cr = cairo_create (mask);
   image = cairo_image_surface_create_for_data (mask_data, CAIRO_FORMAT_A1,
                                                width, height, data_stride);
   cairo_set_source_surface (cr, image, 0, 0);
@@ -935,10 +928,14 @@ gdk_cursor_new_from_pixbuf (GdkDisplay *display,
   cairo_paint (cr);
   cairo_destroy (cr);
  
-  cursor = gdk_cursor_new_from_pixmap (pixmap, mask, &fg, &bg, x, y);
+  cursor = gdk_cursor_new_from_pixmap (display,
+                                       cairo_xlib_surface_get_drawable (pixmap),
+                                       cairo_xlib_surface_get_drawable (mask),
+                                       &fg, &bg,
+                                       x, y);
    
-  g_object_unref (pixmap);
-  g_object_unref (mask);
+  cairo_surface_destroy (pixmap);
+  cairo_surface_destroy (mask);
 
   g_free (data);
   g_free (mask_data);
index a4066e8f13218341e0b7b554059e7c68cac2fa8f..0a0f5056611315493b088983b1cc3d819adcf01d 100644 (file)
@@ -31,6 +31,8 @@
 #ifndef __GDK_PRIVATE_X11_H__
 #define __GDK_PRIVATE_X11_H__
 
+#include <cairo-xlib.h>
+
 #include <gdk/gdkcursor.h>
 #include <gdk/gdkprivate.h>
 #include <gdk/x11/gdkwindow-x11.h>
@@ -148,6 +150,9 @@ gboolean _gdk_x11_get_xft_setting (GdkScreen   *screen,
 
 GdkGrabStatus _gdk_x11_convert_grab_status (gint status);
 
+cairo_surface_t * _gdk_x11_window_create_bitmap_surface (GdkWindow *window,
+                                                         int        width,
+                                                         int        height);
 
 extern GdkDrawableClass  _gdk_x11_drawable_class;
 extern gboolean                 _gdk_use_xshm;
index 84bec2d1d59bcea9d5eb9dc35b9c5e948295379f..deaf4498c0ea97cafaf2667329eca2d63e41d67a 100644 (file)
@@ -261,10 +261,10 @@ attach_free_pixmap_handler (cairo_surface_t *surface,
  * pixmap or bitmap in the X11 API.
  * These functions ensure an Xlib surface.
  */
-static cairo_surface_t *
-gdk_x11_window_create_bitmap_surface (GdkWindow *window,
-                                      int        width,
-                                      int        height)
+cairo_surface_t *
+_gdk_x11_window_create_bitmap_surface (GdkWindow *window,
+                                       int        width,
+                                       int        height)
 {
   cairo_surface_t *surface;
   Pixmap pixmap;
@@ -3774,9 +3774,9 @@ gdk_window_update_icon (GdkWindow *window,
 
       if (gdk_pixbuf_get_has_alpha (best_icon))
         {
-          toplevel->icon_mask = gdk_x11_window_create_bitmap_surface (window,
-                                                                      width,
-                                                                      height);
+          toplevel->icon_mask = _gdk_x11_window_create_bitmap_surface (window,
+                                                                       width,
+                                                                       height);
 
           cr = cairo_create (toplevel->icon_mask);
           gdk_cairo_set_source_pixbuf (cr, best_icon, 0, 0);